#!/usr/bin/env python3

import argparse
import os
import shutil
import glob

# Define the file patterns to be copied
filePatterns = ["build-deb-ubuntu-18.04/heimer*.deb",
                "build-deb-ubuntu-20.04/heimer*.deb",
                "build-deb-ubuntu-22.04-qt5/heimer*.deb",
                "build-deb-ubuntu-22.04-qt6/heimer*.deb",
                "build-appimage/Heimer*.AppImage",
                "build-windows-nsis/heimer*win32.exe",
                "build-windows-zip/zip/heimer*-win32.zip",
                "*.tar.gz"]

def copyFiles(sourceDir, targetDir):

    # Create the target directory if it doesn't exist
    if not os.path.exists(targetDir):
        os.makedirs(targetDir)

    # Copy files matching the patterns from the source directory to the target directory
    for pattern in filePatterns:
        files = glob.glob(os.path.join(sourceDir, pattern))
        for filePath in files:
            fileName = os.path.basename(filePath)
            targetPath = os.path.join(targetDir, fileName)
            shutil.copy2(filePath, targetPath)
            print(f"Copied '{fileName}' to '{targetDir}'")

def main():

    # Parse command-line arguments
    parser = argparse.ArgumentParser(description="Copy files from source directory to target directory")
    parser.add_argument("-s", "--source", required=True, help="Source directory path")
    parser.add_argument("-t", "--target", required=True, help="Target directory path")

    args = parser.parse_args()
    copyFiles(args.source, args.target)

if __name__ == "__main__":
    main()
    print("Done.")

